import {Injectable} from "@angular/core";
import { HttpClient,HttpParams } from '@angular/common/http';
import {toPromise} from "rxjs-compat/operator/toPromise";

@Injectable()
export class RollService {
  serveUrl='http://rosterserver.lessonplan.cn'; /*花名册接口*/
  userServerUrl = 'http://accountserver.lessonplan.cn';/*教师用户接口*/
  stuServerUrl = 'http://clientaccountserver.lessonplan.cn';/*学生用户接口*/
  constructor(
    private http: HttpClient,
    // private params:HttpParams
  ) { }
  getDefaultCover():Promise<any> {
    return this.http.get(this.serveUrl+'/class/defaultCover').toPromise().then(res=>{
      return res;
    })
  }//获取封面默认图片
  getClassList(userGuid,Valid,State):Promise<any> {
      return this.http.get(this.serveUrl+'/class/getClassList/'+userGuid,{
        params: new HttpParams().set('Valid',Valid).set('State',State)
      }).toPromise().then(res=>{
        return res;
      })
  }  //获取班级列表
  changClassStatus(classGuid,data):Promise<any> {
    return this.http.put(this.serveUrl+'/class/'+classGuid,data).toPromise().then(res=>{
      return res;
    })
  }//删除或者恢复班级，State(0:恢复,99:删除)
  uploadRoll(addRoll:object):Promise<any> {
    return this.http.post(this.serveUrl+'/class/addclass',addRoll).toPromise().then(res=>{
      return res;
    })
  }//新增班级
  upDateRoll(updatRoll:object):Promise<any>{
    return this.http.post(this.serveUrl+'/class/putclass',updatRoll).toPromise().then(res=>{
      return res;
    })
  }//修改班级
  getUserName(userGuid:string):Promise<any>{
    return this.http.get(this.userServerUrl+"/open/getThisUser",{
      params: new HttpParams().set('PK_UserGuid',userGuid)}).toPromise().then(res=>{
        return res;
    })
  }//获取用户信息
  getNoticeList(classGuid:string,state:any):Promise<any>{
    return this.http.get(this.serveUrl+'/notice',{
      params: new HttpParams().set('class',classGuid).set('state',state)}).toPromise().then(res=>{
        return res;
    })
    }//获取通知列表,state:0||99,0代表现在，99代表删除
  getClassInfo(classGuid:string):Promise<any>{
    return this.http.get(this.serveUrl+'/class/private/',{
      params: new HttpParams().set('classListString','"'+classGuid+'"')
    }).toPromise().then(res=>{
      return res;
    })
  }//获取班级信息
  getStudentlist(classGuid:string):Promise<any>{
    return this.http.get(this.stuServerUrl+'/user/studentlist/'+classGuid).toPromise().then(res=>{
        return res;
    })
  }
  //根据班级ID获取学生列表
  uploadNotice(notice:object):Promise<any>{
    return this.http.post(this.serveUrl+'/notice',notice).toPromise().then(res=>{
      return res ;
    })
  }
  //添加通知
  deleteNotice(noticeGuid:string):Promise<any>{
    return this.http.delete(this.serveUrl+'/notice/'+noticeGuid).toPromise().then(res=>{
      return res;
    })
  }//删除通知
  recoverNotice(noticeGuid:string):Promise<any>{
    return this.http.put(this.serveUrl+'/notice/recovery/'+noticeGuid,'').toPromise().then(res=>{
      return res;
    })
  }//恢复通知
  updateNotice(noticeGuid:string,data):Promise<any>{
    return this.http.put(this.serveUrl+'/notice/'+noticeGuid,data).toPromise().then(res=>{
      return res;
    })
  }//修改通知
  getNoticeStudentList(noticeGuid:string):Promise<any>{
    return this.http.get(this.stuServerUrl+'/user/notice/'+noticeGuid).toPromise().then(res=>{
      return res;
    })
  }//根据公告Guid获取能够查看学生列表
   getUserInfo(userGuid:string):Promise<any>{
    return this.http.get(this.userServerUrl+'/open/getThisUser',{
      params: new HttpParams().set('PK_UserGuid',userGuid)}).toPromise().then(res=>{
        return res ;
    })
    }
  /*根据用户Guid获取用户详细信息*/
  deleteIMG(url:string):Promise<any>{
    return this.http.delete('http://upload.lessonplan.cn/clear?imgUrl='+url).toPromise().then(res=>{
      return res;
    })
  }
  /*删除封面图片接口*/
}


